printf() and scanf() function

Home / C Programming / printf() and scanf() function

printf() and scanf() function


printf() and scanf() in C

The printf() and scanf() functions are used for input and output in C language. Both functions are inbuilt library functions, defined in stdio.h (header file).

printf() function

The printf() function is used for output. It prints the given statement to the console.

The syntax of printf() function is given below:


 printf("format string",argument_list); 

 The format string can be %d(integer),%c(character),%f(float),%s(string).

  


scanf() function

The scanf() function is used for input. It reads the input data from the console.

The syntax of scanf() function is given below:


scanf("format string",&argument_list);


program for print the cude of given number


  1. #include<stdio.h>    
  2. int main(){    
  3. int number;    
  4. printf("enter a number:");    
  5. scanf("%d",&number);    
  6. printf("cube of number is:%d ",number*number*number);    
  7. return 0;  
  8. }    

OUTPUT


enter a number:5
cube of number is:125